package controls{
	import flash.display.Shape;
	import flash.geom.Point;
	
	
	public class LineDescriptor extends Shape {
		
		private var _start:Point;
		private var _end:Point;
		
		public function LineDescriptor(start:Point, end:Point){
			var startX:Number = start.x;
			var startY:Number = start.y;
			var endX:Number = end.x;
			var endY:Number = end.y;
			
			var arrowLength : Number = 10;
			var arrowAngle : Number = Math.PI / 6;
			var lineAngle : Number;
			if(endX - startX != 0)				
				lineAngle = Math.atan((endY - startY) / (endX - startX));
			else{
				if(endY - startY < 0)
					lineAngle = Math.PI / 2;
				else
					lineAngle = 3 * Math.PI / 2;
			}				
			if(endY - startY >= 0 && endX - startX <= 0){
				lineAngle = lineAngle + Math.PI;
			}else if(endY - startY <= 0 && endX - startX <= 0){
				lineAngle = lineAngle + Math.PI;
			}
			//定义三角形
			var angleC : Number = arrowAngle;
			var rimA : Number = arrowLength;
			var rimB : Number = Math.pow(Math.pow(endY - startY,2) + Math.pow(endX - startX,2),1/2);
			var rimC : Number = Math.pow(Math.pow(rimA,2) + Math.pow(rimB,2) - 2 * rimA * rimB * Math.cos(angleC),1/2);
			var angleA : Number = Math.acos((rimB - rimA * Math.cos(angleC)) / rimC);
			
			var leftArrowAngle : Number = lineAngle + angleA;
			var rightArrowAngle : Number = lineAngle - angleA;			
			var leftArrowX : Number = startX + rimC * Math.cos(leftArrowAngle);
			var leftArrowY : Number = startY + rimC * Math.sin(leftArrowAngle);			
			var rightArrowX : Number = startX + rimC * Math.cos(rightArrowAngle);
			var rightArrowY : Number = startY + rimC * Math.sin(rightArrowAngle);
			
			with(graphics){
				lineStyle(1, 0x000000);
				moveTo(start.x, start.y);
				lineTo(end.x, end.y);	
				
				lineTo(leftArrowX, leftArrowY);
				moveTo(end.x, end.y);
				lineTo(rightArrowX, rightArrowY);
			}
		}
		
	}
}